package com.gtw;

import com.gtw.observer.ConcreteObserver;
import com.gtw.observer.ConcreteSubject;
import com.gtw.observer.Observer;
import com.gtw.observer.java.Publisher;
import com.gtw.observer.java.Reader;
import com.gtw.observer.java.TVStation;

public class Client {

    public static void main(String[] args){
        //定义被观察者
        ConcreteSubject subject = new ConcreteSubject();

        //定义观察者
        Observer observer = new ConcreteObserver();

        //被观察者动态的添加观察者
        subject.addObserver(observer);

        //被观察者开始行动
        subject.doSomething();

        //java自带的观察者模式
        Reader reader = new Reader();
        Publisher publisher = new Publisher();
        //注入观察者
        publisher.addObserver(reader);
        publisher.publish("《读者》");
        TVStation tvStation = new TVStation();
        tvStation.addObserver(reader);
        tvStation.play("足球赛");

    }
}
